package com.poly.system.factory;

import com.poly.system.RemoteUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.poly.common.core.domain.R;
import com.poly.system.domain.SysUser;
import com.poly.system.model.LoginUser;

import java.util.List;
import java.util.Map;

/**
 * 用户服务降级处理
 * 
 * @author Yang huijing
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Map<Long, String>> getUserNameMap(List<Long> idList) {
                return R.fail("获取用户名称失败:" + throwable.getMessage());
            }

            @Override
            public R<SysUser> getUserById(Long userId) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getUserList(String NickName, String deptId) {
                return R.fail("获取用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getUserListByIdList(List<Long> idList) {
                return R.fail("获取用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getCacheUserById(List<Long> userIdList) {
                return R.fail("获取缓存用户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getCacheUserName(List<Long> userIdList) {
                return R.fail("获取缓存用户名称失败:" + throwable.getMessage());
            }


        };
    }
}
